import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import models.UserInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: XiShanShan
 * @Description:
 * @Date:Created in 17:24 2021/4/5
 * @Modified By:xss666
 */
public class Test {
    public static void main(String[] args) throws JsonProcessingException {
    Map<String,Object> map=new HashMap<>();
    map.put("state",200);
    map.put("msg","操作成功");

        List<UserInfo> list=new ArrayList<>();
        for (int i = 0; i <3 ; i++) {
            UserInfo userInfo=new UserInfo();
            userInfo.setUsername("name"+i);
            userInfo.setPassword("pwd"+i);
            list.add(userInfo);
        }

    //Jackson 使用
    //1.创建Jackson 对象
        ObjectMapper mapper=new ObjectMapper();
        String result=mapper.writeValueAsString(list); //将 HashMap 转换成字符串
        System.out.println(result);
    }
}
